package com.carrot.gateway.util;

import java.time.*;

/**
 * @description: 日期工具类
 * @author: zl
 * @date: 2023/10/11
 */
public class DateUtils {


    /**
     * unix时间戳转LocalDateTime
     * @param unixTimestamp
     * @return
     */
    public static LocalDateTime unixToLocalDateTime(Object unixTimestamp){

        // 将Unix时间戳转换为Instant对象
        Instant instant = Instant.ofEpochSecond(Long.valueOf(String.valueOf(unixTimestamp)));

        // 将Instant对象转换为LocalDateTime对象
        LocalDateTime localDateTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();

        return localDateTime;
    }

    public static Long getDateTomeDiff(LocalDateTime start,LocalDateTime end){
      return Duration.between(start, end).toMillis();
    }

    public static void main(String[] args) {
        long end = LocalDateTime.of(2023, 10, 16, 16, 0, 0).toEpochSecond(ZoneOffset.UTC);
        long start =Instant.now().getEpochSecond();
        System.out.println(start);
    }
}
